package databaseHandling;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.ImageIcon;
import model.Kategori;
import model.Vare;
import utility.DateFormatter;

/**
 *
 * @author Jeppe
 */
public abstract class KategoriHandler {

    public static ArrayList<Kategori> hentAlleKategorier() throws SQLException {
        ArrayList<Kategori> kategoriList = new ArrayList<>();
        ResultSet rs = DatabaseHandler.getInstance().select("CALL `hentAlleKategorier`()");

        while (rs.next()) {
            System.out.println(rs.getString("katIconURL"));
            kategoriList.add(new Kategori(rs.getInt("katID"), rs.getString("katNavn"), new ImageIcon(KategoriHandler.class.getResource(rs.getString("katIconURL")))));
        }
//        kategoriList.add(new Kategori(1, "MixPakker", new ImageIcon(getClass().getResource("/images/kategoriIcons/Mixpakker.png"))));
//        kategoriList.add(new Kategori(2, "Ispinde og isvafler", new ImageIcon(getClass().getResource("/images/kategoriIcons/Cream.png"))));
//        kategoriList.add(new Kategori(3, "Børneis", new ImageIcon(getClass().getResource("/images/kategoriIcons/Kids.png"))));
//        kategoriList.add(new Kategori(4, "Special-is", new ImageIcon(getClass().getResource("/images/kategoriIcons/GoodForYou.png"))));
//        kategoriList.add(new Kategori(5, "Desserter", new ImageIcon(getClass().getResource("/images/kategoriIcons/Desserts.png"))));
//        kategoriList.add(new Kategori(5, "Limonadeis", new ImageIcon(getClass().getResource("/images/kategoriIcons/refreshment.png"))));
//        kategoriList.add(new Kategori(5, "Liter Is", new ImageIcon(getClass().getResource("/images/kategoriIcons/Bulk-menu-DK.png"))));
//        kategoriList.add(new Kategori(5, "Diverse", new ImageIcon(getClass().getResource("/images/kategoriIcons/Produktoversigt_too_much_vafler_og_boetter_148x162.png"))));

        return kategoriList;
    }

    public static ArrayList<Vare> hentVarerVedKategori(Kategori kategori) throws SQLException, ParseException {
        ArrayList<Vare> vareList = new ArrayList<>();
        ResultSet rs = DatabaseHandler.getInstance().select("CALL `hentVarerVedKategori`('" + DateFormatter.format(Calendar.getInstance(), true) + "', " + kategori.getID() + ")");

        while (rs.next()) {
            vareList.add(new Vare(rs.getString("varEan"), rs.getString("varNavn"), rs.getInt("varPris"), rs.getString("varBeskrivelse"), new ImageIcon(KategoriHandler.class.getResource(rs.getString("varIconURL"))), new Kategori(rs.getInt("katID"), rs.getString("katNavn"), new ImageIcon(KategoriHandler.class.getResource(rs.getString("katIconUrl"))))));
        }

        return vareList;
    }
}
